package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SocWebsiteAddDTO;
import org.jsola.hr.dto.SocWebsiteUpdateDTO;
import org.jsola.hr.entity.SocWebsiteDO;
import org.jsola.hr.query.SocWebsiteQuery;
import org.jsola.hr.service.ISocWebsiteService;
import org.jsola.hr.vo.SocWebsiteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 社保网站与类型
 *
 * @author zhr
 */
@Component
public class SocWebsiteTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocWebsiteService socWebsiteService;

    /**
     * 生成add测试数据
     * @return SocWebsiteAddDTO
     */
    public SocWebsiteAddDTO getSocWebsiteAddDTO(){
        SocWebsiteAddDTO socWebsiteAddDTO = new SocWebsiteAddDTO();
        socWebsiteAddDTO.setDomain(getRandomValue("varchar",500));
        socWebsiteAddDTO.setAreaName(getRandomValue("varchar",50));
        socWebsiteAddDTO.setSyncServiceBeanName(getRandomValue("varchar",50));
        socWebsiteAddDTO.setLoginUrl(getRandomValue("varchar",500));
        socWebsiteAddDTO.setAreaId(SafeKit.getLong(getRandomValue("bigint",11)));
        socWebsiteAddDTO.setType(getRandomValue("varchar",11));
        socWebsiteAddDTO.setUrl(getRandomValue("varchar",500));
        return socWebsiteAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocWebsiteUpdateDTO
     */
    public SocWebsiteUpdateDTO getSocWebsiteUpdateDTO(SocWebsiteVO socWebsiteVO){
        return socWebsiteService.selectDOById(socWebsiteVO.getId(), SITE_ID).to(SocWebsiteUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocWebsiteQuery
     */
    public SocWebsiteQuery getSocWebsiteQuery() {
        SocWebsiteQuery socWebsiteQuery = new SocWebsiteQuery();
        List<SocWebsiteDO> socWebsiteDOList = socWebsiteService.list(new SocWebsiteDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socWebsiteDOList)) {
            SocWebsiteDO socWebsiteDO = socWebsiteDOList.get(0);
            socWebsiteQuery = socWebsiteDO.to(SocWebsiteQuery.class);
        }
        return socWebsiteQuery;
    }

    /**
     * 保存示例
     * @return SocWebsiteVO
     */
    public SocWebsiteVO saveSocWebsiteExample(){
        SocWebsiteAddDTO addDTO = this.getSocWebsiteAddDTO();
        SocWebsiteVO socWebsiteVO = socWebsiteService.save(addDTO,buildTokenUser());
        return socWebsiteVO;
    }


}

